home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok18.lha
/
Profile
/
Demos
/
Prim3.pro
< prev
next >
Wrap
Text File
|
1993-08-15
|
760b
|
43 lines
MODULE Prim3;
FROM InOut IMPORT WriteInt;
CONST n = 1000;
VAR i,f: INTEGER;
(* f: min = 0, max = 168 *)
(* i: min = 2, max = 1000 *)
prims: ARRAY[2..n] OF BOOLEAN;
found: ARRAY[0..n] OF INTEGER;
PROCEDURE Mark(num: LONGINT; d: INTEGER);
(* num: min = 2, max = 29791 *)
(* d: min = 0, max = 10 *)
BEGIN
(* 660 Aufrufe *)
REPEAT
(* 1491 Durchläufe *)
IF (d<f) AND (num*found[d+1]<=n) THEN
Mark(num,d+1)
ELSE
prims[num] := FALSE
END;
num := num * found[d];
UNTIL num>n;
END Mark;
BEGIN
FOR i:=2 TO n DO (* 999 Durchläufe *)
prims[i] := TRUE END;
f := 0;
FOR i:=2 TO n DO
(* 999 Durchläufe *)
IF prims[i] THEN
found[f] := i; WriteInt(i,5);
Mark(i,0);
INC(f);
END;
END;
END Prim3.